﻿using Architecture.API.Application.TraceabilityCommand.DeepProcessingCommand;
using MediatR;
using Traceability.Domain.DeepProcessingDomain;
using Traceability.Domain.Service.DeepProcessingServices;

namespace Architecture.API.Application.TraceabilityCommandHandler.DeepProcessingCommandHandler
{
    /// <summary>
    /// 添加深加工命令创建命令
    /// </summary>
    public class AddDeepProcessingCommandHandler : IRequestHandler<AddDeepProcessingCommand, int>
    {
        /// <summary>
        /// 深加工服务
        /// </summary>
        protected readonly IDeepProcessingService deepProcessingService;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="deepProcessingService">深加工服务</param>
        public AddDeepProcessingCommandHandler(IDeepProcessingService deepProcessingService)
        {
            this.deepProcessingService = deepProcessingService;
        }

        /// <summary>
        /// 添加深加工信息
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<int> Handle(AddDeepProcessingCommand request, CancellationToken cancellationToken)
        {
            return await deepProcessingService.AddDeepProcessing(new DeepProcessing() { TeamsAndGroups=request.TeamsAndGroups,PersonInCharge=request.PersonInCharge,ProductionBatch=request.ProductionBatch,ShoppingId=request.ShoppingId,CreatedBy=request.CreatedBy,CreatedDate=DateTime.Now });
        }
    }
}
